package org.ourgrid.broker.commands.executors;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.ourgrid.broker.BrokerConstants;
import org.ourgrid.broker.commands.SchedulerData;
import org.ourgrid.broker.dao.WorkerDAO;

import br.edu.ufcg.lsd.commune.container.servicemanager.ServiceManager;

public class UpdateSchedulerExecutor implements ISchedulerCommandExecutor {
	
	/**
	 * <UPDATE_SCHEDULER />
	 */
	public void execute(SchedulerData data, ServiceManager manager) {
		
		if (!manager.getDAO(WorkerDAO.class).isSchedulerActionActive()) {
			Future<?> schedulerFuture = manager.scheduleActionToRunOnce(BrokerConstants.SCHEDULER_ACTION_NAME, 
					BrokerConstants.SCHEDULER_INTERVAL, TimeUnit.SECONDS);
			
			manager.getDAO(WorkerDAO.class).setSchedulerFuture(schedulerFuture);
		}
	}
}
